//
//  AppDelegate.m
//  Weibo1
//
//  应用的代理对象
//




#import "AppDelegate.h"
#import "SXOAuthController.h"       //OAuth授权页面
#import "SXAccountTool.h"           //账号
#import "SDWebImageManager.h"       //缓存网络图片
#import "UMSocial.h"                //友盟分享
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc] init];
    self.window.frame = [UIScreen mainScreen].bounds;
    
    //窗口的根控制器是OAuth授权页面
    self.window.rootViewController = [[SXOAuthController alloc] init];
    
    // sandbox path
    NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
    NSString *path = [doc stringByAppendingPathComponent:@"account.archive"];
    
    SXLog(@"%@",doc);
    
    //  2015-04-05 17:13:49.328 Weibo1[73678:1474319]
    // /Users/zhaoyingxin/Library/Developer/CoreSimulator/Devices/2818ED4E-82FF-4684-AF24-73982752473B/data/Containers/Data/Application/073D467A-B77E-4D4E-8B78-26EF2F0B1DA0/Documents
    
    // SXLog(@"%@",path);
    
    // 2015-04-05 17:15:34.716 Weibo1[73820:1476064]
    // /Users/zhaoyingxin/Library/Developer/CoreSimulator/Devices/2818ED4E-82FF-4684-AF24-73982752473B/data/Containers/Data/Application/6B52A250-A18F-406F-87F5-4E58221B09A0/Documents/account.archive
    
    
    
    // get account from NSKeyedUnarchiver
    SXAccount *account = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
    
    // SXLog(@"%@",account);
    // <SXAccount: 0x7fda58c17ab0>
    
    if (account) {
        [self.window switchRootViewController];
    } else {
        self.window.rootViewController = [[SXOAuthController alloc] init];
    }
    
    
    [self.window makeKeyAndVisible];
    
    //友盟分享
    [UMSocialData setAppKey:@"551ab210fd98c596b3000aee"];
    
    return YES;
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    
    // get single class
    SDWebImageManager *mgr = [SDWebImageManager sharedManager];
    // cancel all download
    [mgr cancelAll];
    // clear the image in memory
    [mgr.imageCache cleanDisk];
}

@end
